import request from '@/utils/request'
import { baseResponse, Class } from '@/types/public'

// Get all classes
export const getClasses = async () => {
  return (await request.get<baseResponse<Array<Class>>>('Admin/GetClasses')).data
}

// Add a new class
export const addClass = async (className: string) => {
  return (
    await request.post<baseResponse<boolean>>(
      'Admin/AddClass',
      { className }
    )
  ).data
}

// Update a class
export const updateClass = async (oldClassName: string, newClassName: string) => {
  return (
    await request.put<baseResponse<boolean>>(
      'Admin/UpdateClass',
      { oldClassName, newClassName }
    )
  ).data
}

// Delete a class
export const deleteClass = async (className: string) => {
  return (
    await request.delete<baseResponse<boolean>>(
      `Admin/DeleteClass?className=${className}`
    )
  ).data
}
